package com.controller.user;

import com.controller.BaseController;
import com.controller.BaseResponse;
import com.controller.user.request.UserRequest;
import com.service.user.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * Created by dawn on 2017/11/3.
 */
@RestController
@RequestMapping(value = "user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    // 登录
    @ApiOperation(value = "账号登陆",notes = "账号登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户名字", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "password", value = "用户密码", required = true, dataType = "String", paramType = "path")
    })
    @GetMapping("/login/{name}/{password}")
    public Object login(@PathVariable(name = "name")  String name,
                        @PathVariable(name = "password") String password) {
        BaseResponse response = userService.login(name, password);
        return response;
    }

    // 注册
    @ApiOperation(value = "注册账号",notes = "注册账号")
    @PostMapping("/registe")
    public Object registe(@Valid @RequestBody UserRequest request) {
        BaseResponse response = userService.registe(request);
        return response;
    }

    // 修改密码
    @ApiOperation(value = "修改密码",notes = "修改密码")
    @PostMapping("/update")
    public Object update(@Valid @RequestBody  UserRequest request) {
        BaseResponse response = userService.update(request);
        return response;
    }

}

